GdkEvent *history_event)
{
GdkMotionEvent *self = (GdkMotionEvent *) event;
- GdkTimeCoord *hist;
+ GdkTimeCoord hist;
GdkDevice *device;
gint i, n_axes;
g_assert (GDK_IS_EVENT_TYPE (event, GDK_MOTION_NOTIFY));
g_assert (GDK_IS_EVENT_TYPE (history_event, GDK_MOTION_NOTIFY));
- hist = g_new0 (GdkTimeCoord, 1);
-
device = gdk_event_get_device (history_event);
n_axes = gdk_device_get_n_axes (device);
for (i = 0; i <= MIN (n_axes, GDK_MAX_TIMECOORD_AXES); i++)
- gdk_event_get_axis (history_event, i, &hist->axes[i]);
+ gdk_event_get_axis (history_event, i, &hist.axes[i]);
+
+ if (G_UNLIKELY (!self->history))
+ self->history = g_array_new (FALSE, TRUE, sizeof (GdkTimeCoord));
+
+ g_array_append_val (self->history, hist);
- self->history = g_list_prepend (self->history, hist);
}
void
g_clear_object (&self->tool);
g_clear_pointer (&self->axes, g_free);
- g_list_free_full (self->history, g_free);
+ if (self->history)
+ g_array_free (self->history, TRUE);
GDK_EVENT_SUPER (event)->finalize (event);
}
/**
* gdk_motion_event_get_history:
* @event: (type GdkMotionEvent): a motion #GdkEvent
+ * @out_n_coords: (out): Return location for the length of the returned array
*
* Retrieves the history of the @event motion, as a list of time and
* coordinates.
* Returns: (transfer container) (element-type GdkTimeCoord) (nullable): a list
* of time and coordinates
*/
-GList *
-gdk_motion_event_get_history (GdkEvent *event)
+GdkTimeCoord *
+gdk_motion_event_get_history (GdkEvent *event,
+ guint *out_n_coords)
{
GdkMotionEvent *self = (GdkMotionEvent *) event;
g_return_val_if_fail (GDK_IS_EVENT (event), NULL);
g_return_val_if_fail (GDK_IS_EVENT_TYPE (event, GDK_MOTION_NOTIFY), NULL);
+ g_return_val_if_fail (out_n_coords != NULL, NULL);
+
+ if (self->history &&
+ self->history->len > 0)
+ {
+ GdkTimeCoord *result;
- return g_list_reverse (g_list_copy (self->history));
+ *out_n_coords = self->history->len;
+
+ result = g_malloc (sizeof (GdkTimeCoord) * self->history->len);
+ memcpy (result, self->history->data, sizeof (GdkTimeCoord) * self->history->len);
+
+ return result;
+ }
+
+ *out_n_coords = 0;
+ return NULL;
}
/* }}} */
double y;
double *axes;
GdkDeviceTool *tool;
- GList *history;
+ GArray *history; /* <GdkTimeCoord> */
};
/*
/*
* GdkProximityEvent:
- * @tool: the #GdkDeviceTool associated to the event
+ * @tool: the #GdkDeviceTool associated to the event
*
* A proximity event indicates that a tool of a graphic tablet, or similar
* devices that report proximity, has moved in or out of contact with the
double x,
double y,
double *axes);
-
+
GdkEvent * gdk_motion_event_new (GdkSurface *surface,
GdkDevice *device,
GdkDevice *source_device,
double y,
GdkCrossingMode mode,
GdkNotifyType notify);
-
+
GdkEvent * gdk_proximity_event_new (GdkEventType type,
GdkSurface *surface,
GdkDevice *device,
double y,
double *axes,
gboolean emulating);
-
+
GdkEvent * gdk_touchpad_event_new_swipe (GdkSurface *surface,
GdkDevice *device,
GdkDevice *source_device,
{
GdkEvent *event;
GArray *backlog_array;
- GList *history = NULL, *l;
+ GdkTimeCoord *history = NULL;
+ guint n_coords = 0, i;
g_return_val_if_fail (GTK_IS_GESTURE_STYLUS (gesture), FALSE);
g_return_val_if_fail (backlog != NULL && n_elems != NULL, FALSE);
event = gesture_get_current_event (gesture);
if (event && GDK_IS_EVENT_TYPE (event, GDK_MOTION_NOTIFY))
- history = gdk_motion_event_get_history (event);
+ history = gdk_motion_event_get_history (event, &n_coords);
+
if (!history)
return FALSE;
backlog_array = g_array_new (FALSE, FALSE, sizeof (GdkTimeCoord));
- for (l = history; l; l = l->next)
+ for (i = 0; i < n_coords; i++)
{
- GdkTimeCoord *time_coord = l->data;
+ GdkTimeCoord *time_coord = &history[i];
graphene_point_t p;
g_array_append_val (backlog_array, *time_coord);
*n_elems = backlog_array->len;
*backlog = (GdkTimeCoord *) g_array_free (backlog_array, FALSE);
- g_list_free (history);
+ g_free (history);
return TRUE;
}